/**
 *  放入app防止首次出现问题缓存的问题
 * @type {{requestInterceptor: interceptor.requestInterceptor}}
 */
var interceptor={
    /**
     * 请求拦截
     * @param req
     * @param res
     * @param next
     */
    requestInterceptor : function(req, res){
        var url = req._parsedUrl.pathname;
        var returnUrl = req.url;
        if (req.headers.token !== undefined && req.headers.token !== "") {
            req.session.token = req.headers.token;
            req.session.appCode = req.headers.appcode;
        }else if(req.query.token != "" && req.query.token != undefined){
            req.session.token = req.query.token;
            req.session.openID = req.query.openID;
        }
        if(req.query.appCode!=''&&req.query.appCode != undefined){
            if(req.query.appCode==""){
                req.session.appCode ="HC_PUB_WX";
            }else{
                req.session.appCode = req.query.appCode;
            }
        }
        if(req.session.appCode==undefined){
            req.session.appCode ="HC_PUB_WX";
        }
        if(req.query.openID!=''&&req.query.openID != undefined){
            req.session.openID = req.query.openID;
        }
        if(req.query.zoneCode!=''&&req.query.zoneCode != undefined){
            req.session.zoneCode = req.query.zoneCode;
            if(req.query.zoneCode=="350500"){
                req.session.zoneCode ="350503"
            }
        }
        req.session.save();
        console.log("zoneCode："+req.session.zoneCode);
        console.log("取得的token："+req.session.token);
        console.log("取得的appCode："+req.session.appCode);
        console.log("取得的openID："+req.session.openID);
    }
};
module.exports = interceptor;